﻿using System;
using System.Collections.Generic;
using System.Linq;
using Reactor.Messaging;
using Reactor.Providers;

namespace Reactor.Entities
{
    public class ReactorCoreEntity : ServiceEntityBase
    {
        #region Fields

        private readonly ICoreDataProvider _coreDataProvider;

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="ReactorCoreEntity"/> class.
        /// </summary>
        /// <param name="coreDataProvider">The core data provider.</param>
        public ReactorCoreEntity(ICoreDataProvider coreDataProvider)
        {
            if (coreDataProvider == null) throw new ArgumentNullException("coreDataProvider");

            _coreDataProvider = coreDataProvider;
        }

        /// <summary>
        /// Gets a list of all services managed by this core.
        /// </summary>
        /// <value>The managed services.</value>
        public IEnumerable<ReactorServiceEntity> GetManagedServices()
        {
            var results = _coreDataProvider.GetAllServiceInstancesAssignedToCore(Identifier);
            return results.ToArray();
        }

        public PointToPointChannel GetPrimaryInputQueue()
        {
            return new PointToPointChannel(Identifier.Name);
        }
    }
}
